package map.android.baidu.carpool.reservation;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import map.android.baidu.carpool.widget.wheel.AbstractWheelTextAdapter;

/**
 * Adapter class for old wheel adapter (deprecated WheelAdapter class).
 * 
 */
public class MinsWheelAdapter extends AbstractWheelTextAdapter {

	private List<Integer> mMinsData = new ArrayList<Integer>();

	public void setData(List<Integer> minsData) {
		mMinsData = minsData;
		notifyDataInvalidatedEvent();
	}

	public List<Integer> getData() {
		return mMinsData;
	}

	public MinsWheelAdapter(Context context) {
		super(context);
	}

	public int getItemValue(int index) {
		if (index >= 0 && index < getItemsCount()) {
			Integer integer = mMinsData.get(index);
			int value = integer.intValue();
			return value;
		}

		return 0;
	}

	@Override
	public CharSequence getItemText(int index) {
		int value = getItemValue(index);
		if (value == Integer.MAX_VALUE) {
			return "";
		}
		String str = intToString(value);

		return str;
	}

	private String intToString(int i) {
		String str = i < 10 ? "0" + i : "" + i;
		return str;
	}

	@Override
	public int getItemsCount() {
		if (mMinsData == null) {
			return 0;
		}

		return mMinsData.size();
	}

}
